home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / manage / snmp / mit / bsd / systm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  4.5 KB  |  213 lines

  1.  
  2. /*
  3.  *    $Header: systm.c,v 3.0 91/05/17 16:14:13 jrd Rel $
  4.  *    Author: J. Davin
  5.  *    Copyright 1988, 1989, Massachusetts Institute of Technology
  6.  *    See permission and disclaimer notice in file "notice.h"
  7.  */
  8.  
  9. #include    <notice.h>
  10.  
  11. #include    <sys/param.h>
  12. #include    <sys/types.h>
  13. #include    <sys/time.h>
  14. #include    <nlist.h>
  15. #include    <stdio.h>
  16.  
  17. #include    <ctypes.h>
  18. #include    <local.h>
  19. #include    <debug.h>
  20. #include    <miv.h>
  21. #include    <asn.h>
  22. #include    <mix.h>
  23. #include    <systm.h>
  24. #include    <kmem.h>
  25.  
  26. #define            systmStringSize        (2 * MAXHOSTNAMELEN)
  27.  
  28. static    CCharType    systmDescrText [ systmStringSize ];
  29. static    CCharType    systmHostName [ (MAXHOSTNAMELEN + 1) ];
  30. static    MivStrType    systmDescrStr;
  31.  
  32. static    CByteType    systmObjId [ systmStringSize ];
  33. static    MivStrType    systmIdStr;
  34.  
  35. static    struct    timeval    systmBootTime;
  36.  
  37. static    MixStatusType    systmTimeRelease (mix)
  38.  
  39. MixCookieType        mix;
  40.  
  41. {
  42.     mix = mix;
  43.     return (smpErrorGeneric);
  44. }
  45.  
  46.  
  47. static    MixStatusType    systmTimeNoSet (mix, name, namelen, value)
  48.  
  49. MixCookieType        mix;
  50. MixNamePtrType        name;
  51. MixLengthType        namelen;
  52. AsnIdType        value;
  53.  
  54. {
  55.     mix = mix;
  56.     name = name;
  57.     namelen = namelen;
  58.     value = value;
  59.     return (smpErrorReadOnly);
  60. }
  61.  
  62. static    MixStatusType    systmTimeCreate (mix, name, namelen, value)
  63.  
  64. MixCookieType        mix;
  65. MixNamePtrType        name;
  66. MixLengthType        namelen;
  67. AsnIdType        value;
  68.  
  69. {
  70.     mix = mix;
  71.     name = name;
  72.     namelen = namelen;
  73.     value = value;
  74.     return (smpErrorGeneric);
  75. }
  76.  
  77. static    MixStatusType    systmTimeDestroy (mix, name, namelen)
  78.  
  79. MixCookieType        mix;
  80. MixNamePtrType        name;
  81. MixLengthType        namelen;
  82.  
  83. {
  84.     mix = mix;
  85.     name = name;
  86.     namelen = namelen;
  87.     return (smpErrorGeneric);
  88. }
  89.  
  90. static    AsnIdType    systmTimeGet (mix, name, namelen)
  91.  
  92. MixCookieType        mix;
  93. MixNamePtrType        name;
  94. MixLengthType        namelen;
  95.  
  96. {
  97.     struct    timeval        now;
  98.     CUnslType        uptime;
  99.  
  100.     mix = mix;
  101.     if ((namelen != (MixLengthType) 1) ||
  102.         (*name != (MixNameType) 0)) {
  103.         return ((AsnIdType) 0);
  104.     }
  105.     else {
  106.         (void) gettimeofday (& now, (struct timezone *) 0);
  107.         uptime = (CUnslType) (now.tv_sec - systmBootTime.tv_sec) *
  108.             (CUnslType) 100;
  109.         return (asnUnsl (asnClassApplication, (AsnTagType) 3, uptime));
  110.     }
  111. }
  112.  
  113. static    AsnIdType    systmTimeNext (mix, name, namelenp)
  114.  
  115. MixCookieType        mix;
  116. MixNamePtrType        name;
  117. MixLengthPtrType    namelenp;
  118.  
  119. {
  120.     struct    timeval        now;
  121.     CUnslType        uptime;
  122.  
  123.     mix = mix;
  124.     if (*namelenp != (MixLengthType) 0) {
  125.         return ((AsnIdType) 0);
  126.     }
  127.     else {
  128.         *namelenp = (MixLengthType) 1;
  129.         *name = (MixNameType) 0;
  130.         DEBUG2 ("systmTimeNext: boot %d %d\n",
  131.             systmBootTime.tv_sec,
  132.             systmBootTime.tv_usec);
  133.         (void) gettimeofday (& now, (struct timezone *) 0);
  134.         DEBUG2 ("systmTimeNext: now %d %d\n",
  135.             now.tv_sec,
  136.             now.tv_usec);
  137.         uptime = (CUnslType) (now.tv_sec - systmBootTime.tv_sec) *
  138.             (CUnslType) 100;
  139.         DEBUG1 ("systmTimeNext: uptime %d\n", uptime);
  140.         return (asnUnsl (asnClassApplication, (AsnTagType) 3, uptime));
  141.     }
  142. }
  143.  
  144. static    MixOpsType    systmTimeOps    = {
  145.  
  146.             systmTimeRelease,
  147.             systmTimeCreate,
  148.             systmTimeDestroy,
  149.             systmTimeNext,
  150.             systmTimeGet,
  151.             systmTimeNoSet
  152.  
  153.             };
  154.  
  155. CVoidType        systmInit ()
  156.  
  157. {
  158.     long        gethostid ();
  159.     int        gethostname ();
  160.     long        hostid;
  161.     struct    nlist    nl [ 2 ];
  162.  
  163.     CCharType    playArea [ systmStringSize ];
  164.     CIntfType    k;
  165.  
  166.     if (gethostname ((char *) systmHostName, (int) MAXHOSTNAMELEN) < 0) {
  167.         (void) sprintf (systmDescrText, "Unknown BSD Unix Host");
  168.     }
  169.     else {
  170.         systmHostName [ MAXHOSTNAMELEN ] = (CCharType) 0;
  171.         (void) sprintf (systmDescrText, "BSD Unix Host %s",
  172.             systmHostName);
  173.     }
  174.  
  175.     systmDescrStr.mivStrData = (CBytePtrType) systmDescrText;
  176.     systmDescrStr.mivStrMaxLen = (CUnsfType) systmStringSize;
  177.     systmDescrStr.mivStrLen = (CUnsfType) strlen (systmDescrText);
  178.  
  179.     (void) mivStringRO ((MixNamePtrType) "\53\6\1\2\1\1\1",
  180.         (MixLengthType) 7, & systmDescrStr);
  181.  
  182.     hostid = gethostid ();
  183.     DEBUG1 ("systmInit: Hostid %d\n", hostid);
  184.     /* enterprises 1.3.6.1.4.1; mit 20; lcs 1    */
  185.     (void) sprintf (playArea, "1.3.6.1.4.1.20.1.%u", hostid);
  186.     k = oidEncode (systmObjId, (CIntfType) systmStringSize, playArea);
  187.     if (k > (CIntfType) 0) {
  188.         systmIdStr.mivStrData = systmObjId;
  189.         systmIdStr.mivStrMaxLen = (CUnsfType) systmStringSize;
  190.         systmIdStr.mivStrLen = (CUnsfType) k;
  191.  
  192.         (void) mivObjectIdRO ((MixNamePtrType) "\53\6\1\2\1\1\2",
  193.             (MixLengthType) 7, & systmIdStr);
  194.     }
  195.  
  196.     nl [ 0 ].n_name = "_boottime";
  197.     nl [ 1 ].n_name = (char *) 0;
  198.  
  199.     if (nlist ("/vmunix", nl) == 0) {
  200.         (void) kmemRead ((CBytePtrType) & systmBootTime,
  201.             (CIntfType) sizeof (systmBootTime),
  202.             (CUnslType) nl [ 0 ].n_value);
  203.     }
  204.     else {
  205.         systmBootTime.tv_sec = (long) 0;
  206.         systmBootTime.tv_usec = (long) 0;
  207.     }
  208.  
  209.     (void) misExport ((MixNamePtrType) "\53\6\1\2\1\1\3",
  210.         (MixLengthType) 7, & systmTimeOps, (MixCookieType) 0);
  211. }
  212.  
  213.